<template>
  <div id="container">
    <el-form :model="form" status-icon  ref="form" label-width="100px" class="demo-ruleForm">
        <el-form-item label="账户" prop="pass">
        <el-input type="text" v-model="form.username" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="checkPass">
        <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
        <el-button type="primary" @click="preg">用户注册</el-button>
        <el-button type="primary" @click="dreg">医生注册</el-button>
    </el-form-item>
</el-form>
  </div>
</template>

<script>
export default {
    data(){
        return{
            form:{
                username:"患者1",
                password:"111",
            }

        };
    },
    methods:{
        login(){     
            this.$axios.post("http://localhost:8000/auth-serv/author/login",this.form).then((response) => {
                let r = response.data;
                if(r.code == 200) {                      

                    let info = JSON.stringify(r.data);
                    sessionStorage.setItem("u", info);
                    sessionStorage.setItem("token",r.msg);

                    this.$message.success("登录成功");

                    let flag=r.data.flag;



                    if(flag==1){
                    this.$router.push("/Admin_home");
                    return;
                    };
                    if(flag==2){
                    this.$router.push("/Doc_home");
                    return;
                    };
                    if(flag==3){
                    this.$router.push("/Pat_home");
                    return;
                    };
                    if(flag==4){
                    this.$message.error("该账户已冻结，详情联系管理员！");
                    return;
                    };
                } 

                this.$message.error("用户名或者密码错误，请重试");
                this.form.username = this.form.password = "";
            });
        },
        //患者注册
        preg(){
            this.$router.push("/Pat_reg");
        },
        //医生注册
        dreg(){
            this.$router.push("/Doc_reg");
        },

    }

}
</script>

<style>
    #container{
        width: 600px;
        margin: auto;
        margin-top: 150px;
    }

</style>